package com.hllxd.hism.passport.login.gateway.error;

//import com.hualala.commons.errorcode.EndType;
//import com.hualala.commons.errorcode.ErrorCode;
//import com.hualala.commons.errorcode.ServiceEntity;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by geran on 16/10/12.
 */
public enum PassportErrorCode implements ErrorCode {
    SUCCESS("000","",false,false),

    INTERNAL_ERROR("00000000", "内部错误", false, false),
    ACCESS_TOKEN_INVALID("00000001", "token失效", false, false),
    USER_AUTHENTICATE_FAILED("00000002", "user验证失败", false, false),
    CAN_NOT_MANIPULATE_GROUP_ACCOUNT("00000003", "不能修改集团账号", false, false),
    DYNAMIC_CODE_SEND_FAIL("00000004", "验证码下发失败", false, false),
    USER_NOT_EXIT("00000005", "用户不存在，没有手机号码与用户对应", false, false),
    NOT_YET_SCAN_QR_CODE("00000006", "还未扫码登录", false, true),
    DYNAMIC_CODE_VERIFICATION_COUNT_OUT_LIMIT("00000007", "您尝试次数过多，暂停登录10分钟", false, false),
    COMPANY_WECHAT_ACCESSTOKEN_FAILED("00000008", "ACCESSTOKEN请求失败", false, false),
    COMPANY_WECHAT_LOGON_FAILED("00000009", "登录企业微信后台失败", false, false),
    COMPANY_WECHAT_SESSION_FAILED("00000010", "session请求失败", false, false);


    private String code;
    private String message;
    private boolean success;
    private boolean retriable;

    private static final Map<String, PassportErrorCode> errorCodeMap;
    static {
        errorCodeMap = new HashMap<String, PassportErrorCode>();
        for(PassportErrorCode passportErrorCode: values()) {
            errorCodeMap.put(passportErrorCode.getCode(), passportErrorCode);
        }
    }
    private PassportErrorCode(String code, String message, boolean success, boolean retriable) {
        this.code = code;
        this.message = message;
        this.success = success;
        this.retriable = retriable;
    }

    @Override
    public String getCode() {
//        return EndType.SERVER.getCode() + ServiceEntity.PASSPORT.getCode() + this.code;
        return this.code;
    }

    @Override
    public String getMessage() {
        return this.message;
    }

    @Override
    public boolean isRetriable() {
        return this.retriable;
    }

    @Override
    public boolean isSuccess() {
        return this.success;
    }

    public static PassportErrorCode getPassportErrorCodeByCode (String code) {
        return errorCodeMap.get(code);
    }
}
